package cn.aicnn.chatssespringboot.persistence;

import cn.aicnn.chatssespringboot.dto.Account;
import cn.aicnn.chatssespringboot.dto.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface accountMapper extends BaseMapper<Account> {
    // 自定义方法：根据用户名查询用户信息
    @Select("SELECT * FROM account WHERE username = #{username}")
    Account selectByUsername(@Param("username") String username);
    @Update("UPDATE account SET username = #{newUsername}, password = #{password}, phone = #{phone}, address = #{address}, firstname = #{firstname}, lastname = #{lastname}, question = #{question}, answer = #{answer} WHERE username = #{username}")
    void updateAccountInfo(Account account);
    // 自定义方法：更新用户信息
    @Update("UPDATE account SET password = #{password}, phone = #{phone}, address = #{address}, firstname = #{firstname}, lastname = #{lastname}, admin = #{admin}, question = #{question}, answer = #{answer}, money = #{money}, borrowBookNum = #{borrowBookNum} WHERE username = #{username}")
    int updateUserInfo(Account account);
    // 自定义方法：根据用户名查询用户安全问题
    @Select("SELECT question FROM account WHERE username = #{username}")
    String selectQuestionByUsername(@Param("username") String username);
    // 自定义方法：根据用户名查询用户安全问题答案
    @Select("SELECT answer FROM account WHERE username = #{username}")
    String selectAnswerByUsername(@Param("username") String username);    // 自定义方法：根据用户名和安全问题答案查询用户
    @Select("SELECT * FROM account WHERE username = #{username} AND answer = #{answer}")
    Account selectByUsernameAndAnswer(@Param("username") String username, @Param("answer") String answer);

    @Update("UPDATE account SET address = #{address} WHERE username = #{username}")
    int updateAddressByUsername(@Param("username") String username, @Param("address") String address);
}
